package org.pzy.springboot;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pzy.springboot.config.ThreadPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: DRevelation
 * @Date: 2022/7/20 15:39
 */
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @Slf4j
    @RestController
    static class HomeController {

        @Autowired
        private ThreadPoolTaskScheduler taskScheduler;

        @GetMapping("/")
        public User index() {
            taskScheduler.scheduleWithFixedDelay(() -> log.info("===>123"), 2000);
            return User.builder().name("哈哈").build();
        }

        @PostMapping("/re")
        public String re(@RequestBody User user) {
            return user.toString();
        }
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonInclude(JsonInclude.Include.NON_NULL)
    static
    class User {
        private String name;
        private String password;
    }
}
